﻿//
// Created by PC on 2022/10/26.
// 荷兰国旗, 分成小于等于区和大于区,以数组的第一个的最后一个值为界
//
#include <iostream>
#include "arrUtil.h"

using namespace std;

void flag(int *a, int length, int &less, int &big)
{
    int value = a[length - 1];
    int i = 0;
    while (i < big )
    {
        if (value < a[i])
        {
            swap(a[i], a[less + 1]);
            i++;
            less++;
        } else if (value > a[i])
        {
            swap(a[i], a[big - 1]);
            big--;
        } else
        {
            i++;
        }
    }
    swap(a[i],a[length-1]);
}

int main()
{
    int arr[] = {9, 8, 7, 6, 0, 4, 3, 2, 1, 5};
    int len = 10;
    printArr(arr,len);
    int l = -1, b = len-1;
    flag(arr,len,l,b);
    printArr(arr,len);
    return 0;
}

